package com.shop.controller;

import com.shop.pojo.UserAddress;
import com.shop.result.JsonResult;
import com.shop.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/address")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    /*用户地址查询*/
    @RequestMapping("/queryUserOrderByCondition")
    @ResponseBody
    public JsonResult queryUserOrderByCondition(HttpServletRequest request,HttpServletResponse response) throws Exception {
        List<UserAddress> userAddressList = userAddressService.queryUserOrderByCondition(request,response);
        return new JsonResult(true,userAddressList,null,userAddressList.size());
    }

    /*用户地址添加*/
    @RequestMapping("/addAddressByUserToken")
    @ResponseBody
    public JsonResult addAddressByUserToken(HttpServletRequest request,HttpServletResponse response) throws Exception{
        String msg = userAddressService.addUserAddress(request,response);
        return new JsonResult(true,msg);
    }

    /*用户地址更新*/
    @RequestMapping("/updateAddressByUserToken")
    @ResponseBody
    public JsonResult updateAddressByUserToken(HttpServletRequest request,HttpServletResponse response) throws Exception{
        String msg = userAddressService.updateUserAddress(request,response);
        return new JsonResult(true,msg);
    }

    /*用户地址删除*/
    @RequestMapping("/deleteAddressByUserToken")
    @ResponseBody
    public JsonResult deleteAddressByUserToken(HttpServletRequest request,HttpServletResponse response) throws Exception{
        String msg = userAddressService.deleteUserAddress(request,response);
        return new JsonResult(true,msg);
    }
}
